/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.app.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yanlight.app.dal.dao.AdminBindDAO;
import com.yanlight.app.dal.dao.PayCodeDAO;
import com.yanlight.app.service.PaycodeService;
import com.yanlight.app.dal.entity.AdminBind;
import com.yanlight.app.dal.entity.PayCode;
import com.yanlight.app.response.PaycodeVerifyResponse;

/**
 * 
 * @author haolw
 * @time 2017/12/07
 */
@Service
public class PaycodeServiceImpl implements PaycodeService {
	@Autowired
	private PayCodeDAO payCodeDAO;
	@Autowired
	private AdminBindDAO adminBindDAO;

	@Override
	public PaycodeVerifyResponse verify(String code) {
		PaycodeVerifyResponse response = new PaycodeVerifyResponse();
		PayCode payCode = payCodeDAO.findAvailable(code);
		if (payCode != null) {
			AdminBind binder = adminBindDAO.findByPaycodeId(payCode.getId());
			response = new PaycodeVerifyResponse();
			response.setId(payCode.getId());
			response.setCompanyId(payCode.getCompanyId());
			if (binder != null) {
				response.setBinderId(binder.getAdminId());
			}
		}
		return response;
	}
}
